package com.zt.springkafka;

import com.alibaba.fastjson.JSONObject;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * 消费者
 *
 * @author zt
 * @date 2021/12/23 12:38
 */
@Component
public class EventConsumer {


    @KafkaListener(topics = {"test"})
    public void handleMessage(ConsumerRecord record) {
        if (record == null || record.value() == null) {
            return ;
        }

        Event event = JSONObject.parseObject(record.value().toString(), Event.class);
        System.out.println(event.getMessage());

    }


}
